package com.tencent.qcloud.tim.uikit.modules.group.info;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.tencent.qcloud.tim.uikit.R;
import com.tencent.qcloud.tim.uikit.modules.group.member.GroupMemberManagerFragment;
import com.tencent.qcloud.tim.uikit.utils.TUIKitConstants;

import androidx.annotation.Nullable;


public class GroupInfoActivity extends Activity {
    public static final int TYPE_MEMBER = 999;


    public static void forward(Context context, GroupInfo info){
        Intent intent = new Intent(context, GroupInfoActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt(TUIKitConstants.Group.FORWARD_TYPE, TYPE_MEMBER);
        bundle.putSerializable(TUIKitConstants.Group.GROUP_INFO, info);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.group_info_activity);

        int type = 0;
        if (getIntent().getExtras()!= null){
            type = getIntent().getExtras().getInt(TUIKitConstants.Group.FORWARD_TYPE,0);
        }

        if (type==TYPE_MEMBER) {
            GroupMemberManagerFragment fragment = new GroupMemberManagerFragment();
            fragment.setArguments(getIntent().getExtras());
            getFragmentManager().beginTransaction().replace(R.id.group_manager_base, fragment).commitAllowingStateLoss();
        }else {
            GroupInfoFragment fragment = new GroupInfoFragment();
            fragment.setArguments(getIntent().getExtras());
            getFragmentManager().beginTransaction().replace(R.id.group_manager_base, fragment).commitAllowingStateLoss();
        }

    }

    @Override
    public void finish() {
        super.finish();
        setResult(1001);
    }
}
